package com.wenc.psi.dao;

import androidx.lifecycle.LiveData;

import com.wenc.psi.pojo.Customer;
import com.wenc.psi.pojo.Part;
import com.wenc.psi.utils.JDBCUtils;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CustomerDao extends JDBCUtils implements Dao<Customer>{
    @Override
    public void insert(Customer... customers) {

    }

    @Override
    public void delete(Customer... customers) {

    }

    @Override
    public void delete(String... ids) {

    }

    @Override
    public void update(Customer oldT, Customer newT) {

    }

    @Override
    public List<Customer> getAllData() {
        List<Customer> customerList = new ArrayList<>();
        try {
            conn = getConnection();
            String sql = "SELECT * FROM customer";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            while (rs.next()){
                Customer customer = new Customer();
                customer.setId(rs.getString("id"));
                customer.setName(rs.getString("name"));
                customer.setPinyin(rs.getString("pinyin"));
                customer.setBank(rs.getString("bank"));
                customer.setBankAccount(rs.getString("bankaccount"));
                customer.setPhone(rs.getString("phone"));
                customer.setEmail(rs.getString("email"));
                customer.setQq(rs.getString("email"));
                customer.setWeChat(rs.getString("wechat"));
                customer.setPrepaid(rs.getDouble("prepaid"));
                customer.setUnpaid(rs.getDouble("unpaid"));
                customerList.add(customer);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            close(rs,stmt,conn);
        }
        return customerList;
    }

    @Override
    public Customer getDataById(String id) {
        return null;
    }

    @Override
    public LiveData<List<Customer>> getAllLiveData() {
        return null;
    }
}
